var status;

//需要的背包空间
var solt = 1;

//显示信息
var message = "";

var RandomItem = Array(
		//道具 - 数量
		Array(5150040, 1), //防爆
		Array(5150064, 1), //A级潜能100%
		Array(5150126, 1), //A级潜能100%
		Array(5150100, 1), //2星
		Array(5150119, 1), //3星
		Array(5150135, 1), //4星
		Array(5150139, 1), //5星
		Array(4310234, 30), //魔方
		Array(4310233, 30));

var ItemList = Array();

function start() {
	status = -1;
	item = im.getItemId();
	action(1, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		im.dispose();
	} else {
		if (mode == 0) {
			im.dispose();
			return;
		}
		if (mode == 1) {
			status++;
		} else {
			status--;
		}
		if (status == 0) {
			for (var i = 0; i < RandomItem.length; i++) {
				ItemList.push(RandomItem[i]);
				message += "\r\n#b#i" + RandomItem[i][0] + ":# #t" + RandomItem[i][0] + "#";
			}
			im.sendYesNo("您是否要打开 #b随机箱#k\r\n#d您将会获得以下其中一个物品：\r\n" + message + "\r\n");
		} else if (status == 1) {
			var random = new java.util.Random();
			if (random.nextInt(100) <= 20) {
				var a = rand(1000, 5000);
				im.gainNX(a);
				im.worldSpouseMessage(0x26, "[头脑之神补给箱] : " + im.getPlayer().getName() + " 从中获得了 " + a + "点点卷.运气真的太好啦！");
			} else if (random.nextInt(100) <= 30) {
				var b = rand(1000, 5000);
				im.gainNX(2, b);
				im.worldSpouseMessage(0x26, "[头脑之神补给箱] : " + im.getPlayer().getName() + " 从中获得了 " + b + "点抵用卷.运气真的太好啦！");
			} else if (random.nextInt(100) <= 40) {
				var c = rand(500, 3000);
				im.gainPlayerEnergy(c);
				im.worldSpouseMessage(0x26, "[头脑之神补给箱] : " + im.getPlayer().getName() + " 从中获得了 " + c + "点PPMS微积分.运气真的太好啦！");
			} else if (random.nextInt(100) <= 50) {
				var d = rand(500, 3000);
				im.gainPlayerPoints(d);
				im.worldSpouseMessage(0x26, "[头脑之神补给箱] : " + im.getPlayer().getName() + " 从中获得了 " + d + "点PPMS活跃.运气真的太好啦！");
			} else {
				if (im.getSpace(5) >= solt/* && im.used()*/) {
					var finalchance = random.nextInt(ItemList.length);
					var itemID = ItemList[finalchance][0];
					var count = ItemList[finalchance][1];
					im.gainItem(itemID, count);
					im.worldSpouseMessage(0x26, "[头脑之神补给箱] : " + im.getPlayer().getName() + " 从中获得了 [" + im.getItemName(itemID) + "] x " + count + "运气真的太好啦！");
				} else {
					im.sendOk("您的 #r现金栏#k 空间没有#r#e " + solt + " #n#k个空位！无法获得 \r\n#b#i" + item + ":# #t" + item + "# #k 里的以下物品:\r\n" + message);
				}
			}
			im.used(1);
			im.dispose();
		}
	}
}

function rand(lbound, ubound) {
	return Math.floor(Math.random() * (ubound - lbound)) + lbound;
}
